package com.vdongchina.thread.Lock;

import java.util.concurrent.locks.LockSupport;

/**
 * locksupport 对于 wait/notifiy的优势
 * <p>
 * 1.不需要在同步块中执行
 * <p>
 * 2.unpark()可以优先于 park()执行,而不会堵塞
 * 而 notify不能优先于wait执行,不然会一直堵塞
 */
public class LockSupportDemo {


    public static void main(String[] args) throws Exception {
        final Object obj = new Object();
        Thread A = new Thread(new Runnable() {
            @Override
            public void run() {
                int sum = 0;
                for (int i = 0; i < 100; i++) {
                    sum += i;
                }
                LockSupport.park();
                System.out.println(sum);
            }
        });
        A.start();
        //睡眠一秒钟，保证线程A已经计算完成，阻塞在wait方法
        //Thread.sleep(1000);
        LockSupport.unpark(A);
    }

}
